home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '91 / '91 Attendee Contributions / Brian Fitzgerald's Stuff / cperf / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-21  |  3.2 KB  |  112 lines  |  [TEXT/KAHL]

  1. /* Driver program for the Perfect hash function generator.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  4.  
  5. This file is part of GNU GPERF.
  6.  
  7. GNU GPERF is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU GPERF is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU GPERF; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Simple driver program for the Perfect.hash function generator.
  22.    Most of the hard work is done in class Perfect and its class methods. */
  23.  
  24. #include <stdio.h>
  25. #ifdef THINK_C
  26.     #include <console.h>
  27. #endif
  28.  
  29. #include "stderr.h"
  30. #include "options.h"
  31. #include "perfect.h"
  32. #include "hashtable.h"
  33.  
  34. /*******************************************************************************\
  35. *                              Prototypes                                        *
  36. \*******************************************************************************/
  37.  
  38. int                main( int argc, char ** argv );
  39.  
  40. static void        init_all( int argc, char *argv[] );
  41. static void        destroy_all( void );
  42.  
  43.  
  44.     /***********************************************************************\
  45.     *                                                                        *
  46.     * name:        main                                                        *
  47.     *                                                                        *
  48.     * descr:    Driver for perfect hash function generation.                *
  49.     *                                                                        *
  50.     \***********************************************************************/
  51.  
  52. int main( int argc, char ** argv )
  53. {
  54.     int status;
  55.  
  56.     #ifdef THINK_C
  57.         argc = ccommand( &argv );
  58.     #endif
  59.   
  60.         /* Sets the options. */
  61.  
  62.     init_all( argc, argv );
  63.  
  64.         /*    Generates the perfect hash table.
  65.             Also prints generated code neatly to the output. */
  66.  
  67.     status = perfect_generate();
  68.     destroy_all();
  69.  
  70.     return status;
  71. }
  72.  
  73.  
  74.     /***********************************************************************\
  75.     *                                                                        *
  76.     * name:        init_all                                                    *
  77.     *                                                                        *
  78.     * descr:    Call all initializers.                                        *
  79.     *                                                                        *
  80.     \***********************************************************************/
  81.  
  82. /* Calls the appropriate intialization routines for each
  83.    ADT.  Note that certain initialization routines require
  84.    initialization *after* certain values are computed.  Therefore,
  85.    they cannot be called here. */
  86.    
  87. static void init_all( int argc, char *argv[] )
  88. {
  89.     options_init( argc, argv );    
  90.     key_list_init();
  91.     perfect_init();              
  92. }
  93.  
  94.     /***********************************************************************\
  95.     *                                                                        *
  96.     * name:        destroy_all                                                    *
  97.     *                                                                        *
  98.     * descr:    Call appropriate destruction routines for each ADT.         *
  99.     *            These routines print diagnostics if the debugging option    *
  100.     *            is enabled.                                                    *
  101.     *                                                                        *
  102.     \***********************************************************************/
  103.  
  104. static void destroy_all()
  105. {
  106.     options_destroy();
  107.     bool_array_destroy();
  108.     hash_table_destroy();
  109.     key_list_destroy();
  110.     perfect_destroy();
  111. }
  112.